home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-26 | 4.9 KB | 191 lines | [TEXT/MPS ] |
- // Copyright © 1995 Apple Computer, Inc. All rights reserved.
- // Release Version: $ 1.0 d11 $
-
- //================================================================================
-
- // --- DU FW ---------------------
- #ifndef DULISTPART_H
- #include "DUListPart.h" // DU_CListPart
- #endif
-
- #ifndef DUSELECTABLE_H
- #include "DUSelectable.h" // DU_MSelectable
- #endif
-
- #ifndef DULIST_H
- #include "DUList.h" // DU_CList
- #endif
-
-
- // ----- Framework Layer -----
- #ifndef FWPRESEN_H
- #include "FWPresen.h" // FW_CPresentation
- #endif
-
- // ----- OS Layer -----
- #ifndef FWSUSINK_H
- #include "FWSUSink.h" // FW_CStorageUnitSink
- #endif
-
- // ----- Foundation Layer -----
- #ifndef FWSTREAM_H
- #include <FWStream.h> // FW_InitializeArchiving
- #endif
-
- #include "FWARDyna.h"
-
- // ----- OpenDoc Includes --------------
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh> // kODPropContents
- #endif
-
- //==============================================================================
- DU_CListPart::DU_CListPart( ODPart* odPart,
- ODValueType partKind,
- ODValueType partUserName,
- FW_Instance partInstance,
- FW_ResourceId iconID)
- : FW_CPart(odPart, partKind, partUserName, partInstance, iconID),
- fPartKind(partKind),
- fNumItems(0),
- fItemList(NULL)
- {
- }
-
- //--------------------------------------------------------------------------------
- void
- DU_CListPart::Initialize(Environment* ev) // Override
- {
- FW_CPart::Initialize(ev);
- fItemList = new DU_CList;
- }
-
- //--------------------------------------------------------------------------------
- DU_CListPart::~DU_CListPart()
- {
- DU_MSelectable* item = NULL;
- while ((item = fItemList->FirstItem()) != NULL) {
- fItemList->Remove(item);
- delete item;
- }
- delete fItemList;
- }
-
- //--------------------------------------------------------------------------------
- FW_Boolean
- DU_CListPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar,
- FW_Boolean hasMenuFocus,
- FW_Boolean isRoot) // Override
- {
- if (hasMenuFocus) {
- menuBar->EnableCommand(ev, kODCommandSelectAll, GetNumItems() > 0);
- }
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------
- void
- DU_CListPart::ExternalizeContent(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CCloneInfo* cloneInfo) // Override
- {
- FW_UNUSED(cloneInfo);
-
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, fPartKind, 0, kODPosUndefined);
- storageUnit->Remove(ev);
- storageUnit->AddValue(ev, fPartKind);
-
- FW_CStorageUnitSink suSink(storageUnit, kODPropContents, fPartKind);
- FW_CWritableStream stream(&suSink);
-
- // write number
- stream << fNumItems;
-
- // write each item
- DU_CListIterator iter(fItemList);
- DU_MSelectable* item;
- for (item = iter.First(); iter.IsNotComplete(); item = iter.Next())
- FW_WRITE_DYNAMIC_OBJECT(stream, item, DU_MSelectable);
-
- }
-
- //--------------------------------------------------------------------------------
- void
- DU_CListPart::InternalizeContent(Environment* ev, ODStorageUnit* storageUnit,
- FW_CCloneInfo* cloneInfo) // Override
- {
- FW_UNUSED(cloneInfo);
- ODValueType contentPropertyValueType = this->GetPartKind(ev);
-
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined,
- contentPropertyValueType, 0, kODPosUndefined);
-
- if (storageUnit->GetSize(ev) != 0) {
- FW_CStorageUnitSink sink(storageUnit, kODPropContents,
- contentPropertyValueType);
- FW_CReadableStream stream(&sink);
-
- // read number
- stream >> fNumItems;
-
- // read items; make list
- DU_MSelectable* item = NULL;
- for (long count=0; count < fNumItems; count++) {
- FW_READ_DYNAMIC_OBJECT(stream, &item, DU_MSelectable);
- fItemList->AddLast(item);
- }
- } // if
- }
-
- //--------------------------------------------------------------------------------
- DU_CList*
- DU_CListPart::GetItemList()
- {
- return fItemList;
- }
-
- //--------------------------------------------------------------------------------
- ODSShort
- DU_CListPart::GetNumItems()
- {
- return fNumItems;
- }
-
- //--------------------------------------------------------------------------------
- DU_MSelectable*
- DU_CListPart::FrontItemHit(Environment *ev, FW_CPoint &pt)
- {
- DU_MSelectable* item = NULL;
-
- // Look first for a hit within a selected item
- DU_CListIterator iter(fItemList);
- for (item = iter.Last(); iter.IsNotComplete(); item = iter.Previous()) {
- if (item->IsSelected() && item->Hit(ev, pt))
- return item;
- }
-
- // Look next for a hit within any item
- for (item = iter.Last(); iter.IsNotComplete(); item = iter.Previous()) {
- if (item->Hit(ev, pt))
- return item;
- }
- return NULL;
- }
-
- //--------------------------------------------------------------------------------
- void
- DU_CListPart::AddItem(Environment* ev, DU_MSelectable* item)
- {
- fItemList->AddLast(item);
- fNumItems++;
- }
-
- //--------------------------------------------------------------------------------
- void
- DU_CListPart::RemoveItem(Environment* ev, DU_MSelectable* item)
- {
- fItemList->Remove(item);
- fNumItems--;
- }
-
-